#!/bin/sh

# Copyright (C) 2015-2021, Wazuh Inc.
# OSSEC         Controls Wazuh on Solaris systems
# Author:       Kayvan A. Sylvan <kayvan@sylvan.com>
# Author:       Daniel B. Cid <dcid@ossec.net>
#
# chkconfig: 2345 99 15
# description: Starts and stops Wazuh (Host Intrusion Detection System)
#
# This will work on Solaris systems (maybe others too)
#
# Modified by Chris Cuevas and Darryl Marsee to work on Solaris
#
# Source function library.
LANG=C
export $LANG

WAZUH_HOME=WAZUH_HOME_TMP
WAZUH_CONTROL="$WAZUH_HOME/bin/wazuh-control"

start() {
       echo -n "Starting Wazuh: "
       ${WAZUH_CONTROL} start > /dev/null
       RETVAL=$?
       if [ $RETVAL -eq 0 ]; then
               echo success
       else
               echo failure
       fi
       echo
       return $RETVAL
}

stop() {
       echo -n "Stopping Wazuh: "
       ${WAZUH_CONTROL} stop > /dev/null
       RETVAL=$?
       if [ $RETVAL -eq 0 ]; then
               echo success
       else
               echo failure
       fi
       echo
       return $RETVAL
}

status() {
       ${WAZUH_CONTROL} status
}


case "$1" in
 start)
       start
       ;;
 stop)
       stop
       ;;
 restart)
       stop
       start
       ;;
 status)
   status
       ;;
 *)
       echo "*** Usage: ossec {start|stop|restart|status}"
       exit 1
esac

exit $?
